// 创建路由逻辑
const routes = {
  '/': () => {
    window.location.href = '../html/login.html';
  },
  '/hall': () => {
    window.location.href = '../html/hall.html';
  },
  '/contact': () => {
    viewContainer.innerHTML = '<h2>Contact</h2>';
  },
};

const viewContainer = document.getElementById('view-container');

let lastHash = ''; // 添加一个变量来存储上一次的哈希值

function handleRouteChange() {
  const route = window.location.hash.replace('#', '') || '/';

  // 如果新的哈希值与上一次的哈希值相同，则不进行导航
  if (window.location.hash === lastHash) {
    return;
  }

  const renderFunction = routes[route];
  if (renderFunction) {
    renderFunction();
  } else {
    viewContainer.innerHTML = '<h2>404 - Page not found</h2>';
  }

  lastHash = window.location.hash; // 在导航完成后，更新上一次的哈希值
}

window.addEventListener('hashchange', handleRouteChange);
window.addEventListener('DOMContentLoaded', handleRouteChange);